﻿@model List<CategoryHomeModel>
@using Microsoft.AspNet.Identity;
@{
    ViewBag.Title = "Home Page";
}

<div class="row" style="margin-top: 4%;">

    <div>
        <div class="row">
            @foreach (var item in this.Model)
            {
                foreach (var board in item.Boards)
                {
                    foreach (var pin in board.Pins)
                    {
                        <div class="col-sm-3" style="height: 250px; border: 1px solid white;">
                            <img class="img-responsive" src="@Url.Content(pin.ImageAddress)" />
                            <div class="footer">
                                @if (!pin.AlreadyLiked(User.Identity.GetUserId<int>()))
                                {
                                    <a href="#" class="likeButton" data-pinId="@pin.Id">
                                        <i class="fa fa-heart">
                                            @pin.LikedUserIds.Count()
                                            می پسندم
                                        </i>

                                    </a>
                                }
                                else
                                {
                                    <i class="fa fa-heart-o">
                                        پسندیدم
                                        @pin.LikedUserIds.Count()
                                    </i>
                                }
                            </div>
                            <div class="footer">
                                <a href="#" style="font-family:Tahoma; color:#157de0"
                                   data-remote="/ImagePin/Repin?pinId=@pin.Id"
                                   data-toggle="modal" data-target="#wide">
                                    <img src="~/Content/assets/img/70.svg" />
                                    پین
                                </a>
                            </div>
                        </div>
                    }
                }
            }
        </div>
    </div>
</div>

<div class="modal fade" id="wide" aria-hidden="true" data-backdrop="static" data-keyboard="false">
    <div class="modal-content"></div>
</div>


@if (Request.IsAuthenticated)
{
    <script>
        $('.likeButton').click(function (e) {
            var button = $(this);
            var itemId = button.attr('data-pinId');
            alert(itemId);
            $.ajax({
                type: 'POST',
                url: '/ImagePin/Like',
                data: { id: itemId },
                success: function (data) {
                    alert('done');
                }
            })
        });
    </script>
}